<div class="header">
    <h1 class="page-title">商品列表</h1>
</div>

<div class="well">
    <!-- search button -->
    <form action="goodsList" method="get" class="form-search">
        <div class="row-fluid" style="text-align: left;">
            <div class="pull-left span4 unstyled">
                <p> 商品名称：<input class="input-medium" name="goods_name" value="{$goods_name}" type="text"></p>
                <p> 添加时间：<input class="input-medium" name="create_time" value="{$create_time}" type="date"></p>
            </div>
        </div>
        <button type="submit" class="btn">查找</button>
        <a class="btn btn-primary" href="goodsAdd">新增</a>
        <a class="btn btn-primary" href="goodsExport">导出</a>
    </form>
</div>
<div class="well">
    <!-- table -->
    <table class="table table-bordered table-hover table-condensed">
        <thead>
        <tr>
            <th>编号</th>
            <th>商品名称</th>
            <th>商品价格</th>
            <th>商品状态</th>
            <th>商品数量</th>
            <th>商品logo</th>
            <th>添加时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="data" id="vo"}
            <tr class="success">
                <td>{$vo.id}</td>
                <td><a href="javascript:void(0);">{$vo.goods_name|raw}</a></td>
                <td>{$vo.goods_price}</td>
                <td>
                    {if condition="($vo.goods_state == 1) "}
                        <span style="color: red" data-id="{$vo.id}" data-value="{$vo.goods_state}" class="goods_state">已上架</span>
                    {else /}
                        <span style="color: blue" data-id="{$vo.id}" data-value="{$vo.goods_state}" class="goods_state">已下架</span>
                    {/if}
                </td>
                <td>{$vo.goods_number}</td>
                <td><img src="{$vo.goods_logo}"></td>
                <td>{$vo.create_time}</td>
                <td>
                    <a href="goodsEditor/{$vo.id}"> 编辑 </a>
                    <a href="javascript:void(0);" class="delete" data-id="{$vo.id}"> 删除 </a>
                </td>
            </tr>
        {/volist}

        </tbody>
    </table>
    {$data|raw}
    <!-- pagination -->

</div>

<!-- footer -->
<footer>
    <hr>
    <p>© 2017 <a href="javascript:void(0);" target="_blank">ADMIN</a></p>
</footer>

<script>
    //ajax删除
    $('.delete').click(function () {
        var id = $(this).attr('data-id');

        $.ajax({
            url:"goodsDel/" + id ,
            // data:{id:id},
            // type:'POST',
            dataType:'json',
            success:function (result) {
                if (result.code == 0) {
                    alert(result.msg);
                    location.href = 'goodsList';
                } else {
                    alert(result.msg);
                }
            }
        })

    })
    //ajax修改、即点即改
    $('.goods_state').click(function () {
        var id = $(this).attr('data-id');
        var goods_state = $(this).attr('data-value');
        var that = $(this);
        $.ajax({
            url:"goodsState/" + id ,
            // data:{id:id},
            // type:'POST',
            dataType:'json',
            success:function (result) {
                if (result.code == 0) {
                    //客户端判断
                    if (goods_state == 1) {
                        that.text('已下架');
                        that.attr('data-value',0);
                        that.css('color','blue');
                    } else {
                        that.text('已上架');
                        that.attr('data-value',1);
                        that.css('color','red');
                    }
                } else {
                    alert(result.msg);
                }
            }
        })
    })

</script>